package cate.game.pvp.throne.data.ko;

import cate.common.table.d.GDFight;
import cate.common.table.d.GDThrone;
import cate.game.play.part.PlaySide;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;
import lombok.extern.slf4j.Slf4j;

@NoteClass("当前轮次下注情况")
@Slf4j
public class TBKoCurBet {

	@NoteField("比赛类型")
	public int gameType;

	@NoteField("等级组")
	public int levelGroup;

	@NoteField("轮次")
	public int round;

	@NoteField("匹配分组")
	public int matchGroup;

	@NoteField("a方数据")
	public PlaySide a;

	@NoteField("b方数据")
	public PlaySide b;

	@NoteField("a方投注次数")
	public int betANum;

	@NoteField("b方投注次数")
	public int betBNum;

	@NoteField("a方投注额度")
	public double betACoins;

	@NoteField("b方投注额度")
	public double betBCoins;

	@NoteField("a方赔率")
	public double oddsA;

	@NoteField("b方赔率")
	public double oddsB;



	public void bet(byte team) {
		if (team == GDFight.Team.A) {
			betANum++;
			betACoins += GDThrone.BET_COIN;
		} else {
			betBNum++;
			betBCoins += GDThrone.BET_COIN;
		}
		calBothOdd();
	}

	public void calBothOdd(){
		oddsA = calOdd(b.snapshot.base.power, betBCoins);
		oddsB = calOdd(a.snapshot.base.power, betACoins);
	}


	private double calOdd(double power, double coins) {
		double odd = power / (a.snapshot.base.power + b.snapshot.base.power) + coins / (betACoins + betBCoins + 1);
		return Math.max(0.01d, odd / 2) + 1;
	}

	public void update(SimpleInfo info) {
		if (info == null) {
			return;
		}
		if (info.round != this.round) {
			return;
		}
		this.betANum = info.betANum;
		this.betBNum = info.betBNum;
		this.betACoins = info.betACoins;
		this.betBCoins = info.betBCoins;
		this.oddsA = info.oddsA;
		this.oddsB = info.oddsB;
	}

	public SimpleInfo buildSimple() {
		SimpleInfo info = new SimpleInfo();
		info.round = this.round;
		info.betANum = this.betANum;
		info.betBNum = this.betBNum;
		info.betACoins = this.betACoins;
		info.betBCoins = this.betBCoins;
		info.oddsA = this.oddsA;
		info.oddsB = this.oddsB;
		return info;
	}

	public static class SimpleInfo {

		@NoteField("回合")
		public int round;

		@NoteField("a方投注次数")
		public int betANum;

		@NoteField("b方投注次数")
		public int betBNum;

		@NoteField("a方投注额度")
		public double betACoins;

		@NoteField("b方投注额度")
		public double betBCoins;

		@NoteField("a方赔率")
		public double oddsA;

		@NoteField("b方赔率")
		public double oddsB;
	}

}
